<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="date">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.date"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="班次" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择班次" clearable size="small">
          <el-option
            v-for="dict in typeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="交班时间" prop="shiftTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.shiftTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择交班时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="接班时间" prop="takeTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.takeTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择接班时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="负责人" prop="logUser">
        <el-input
          v-model="queryParams.logUser"
          placeholder="请输入负责人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:log:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:log:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:log:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:log:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="编号" align="center" prop="logId"/>
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="班次" align="center" prop="type" :formatter="typeFormat"/>
      <el-table-column label="交班时间" align="center" prop="shiftTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shiftTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="接班时间" align="center" prop="takeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="负责人" align="center" prop="logUser"/>
      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat">
        <template slot-scope="scope">
          <el-tag :type="(scope.row.status == '0' ? 'warning' : (scope.row.status == '1' ? '' : 'success'))"
                  size="mini">
            {{ scope.row.status == '0' ? '未交班' : (scope.row.status == '1' ? '已交班' : '已接班') }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:log:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:log:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改运行日志对话框 -->
    <el-dialog :title="titleLog" :visible.sync="openLog" width="500px" z-index="101">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="form.date"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="班次">
          <el-radio-group v-model="form.type">
            <el-radio
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{ dict.dictLabel }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="负责人" prop="logUser">
          <el-input v-model="form.logUser" placeholder="请输入负责人"/>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择状态">
            <el-option
              v-for="dict in statusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 填报或修改运行大日志对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      :close-on-click-modal="false"
      append-to-body
      z-index="100"
      :destroy-on-close="false"
      @closed="idChange"
      width="1200px">
      <el-row>
        <el-col :span="24">
          <el-tabs v-model="activeName">
            <el-tab-pane label="日安全例会" name="first"></el-tab-pane>
            <el-tab-pane label="运行记事" name="second"></el-tab-pane>
            <el-tab-pane label="运行方式" name="third"></el-tab-pane>
            <el-tab-pane label="接地线（刀闸）" name="fourth"></el-tab-pane>
            <el-tab-pane label="交接记录" name="fifth"></el-tab-pane>
            <el-tab-pane label="调度命令" name="sixth"></el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
      <el-row v-if="activeName === 'first'">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddWork"
              v-hasPermi="['system:worklist:add']"
            >新增</el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loadingWork" :data="worklistList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="编号" align="center" prop="id" />
          <el-table-column label="工作内容" align="center" prop="text" />
          <el-table-column label="负责人" align="center" prop="user" />
          <el-table-column label="完成情况" align="center" prop="status" :formatter="statusFormatWork" />
          <el-table-column label="日志编号" align="center" prop="logId" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdateWork(scope.row)"
                v-hasPermi="['system:worklist:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:worklist:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <el-form ref="form" :model="formMeet" :rules="rules" label-width="80px">
          <el-form-item label="班前会" prop="preMeeting">
            <el-input v-model="formMeet.preMeeting" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          <el-form-item label="班前会参会人员" prop="preUser">
            <el-input v-model="formMeet.preUser" placeholder="请输入班前会参会人员" />
          </el-form-item>
          <el-form-item label="班后会" prop="postMeeting">
            <el-input v-model="formMeet.postMeeting" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          <el-form-item label="班前会参会人员" prop="postUser">
            <el-input v-model="formMeet.postUser" placeholder="请输入班前会参会人员" />
          </el-form-item>
          <el-form-item label="日志编号" prop="logId">
            <el-input v-model="formMeet.logId" placeholder="请输入日志编号" />
          </el-form-item>
        </el-form>
      </el-row>
      <el-row v-if="activeName === 'second'">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddDiary"
              v-hasPermi="['system:diary:add']"
            >新增
            </el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loadingDiary" :data="diaryList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center"/>
          <el-table-column label="编号" align="center" prop="diaryId"/>
          <el-table-column label="记录类型" align="center" prop="type" :formatter="typeFormatDiary"/>
          <el-table-column label="记录内容" align="center" prop="text"/>
          <el-table-column label="负责人" align="center" prop="userName"/>
          <el-table-column label="日志编号" align="center" prop="logId"/>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdateDiary(scope.row)"
                v-hasPermi="['system:diary:edit']"
              >修改
              </el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:diary:remove']"
              >删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-row v-if="activeName === 'third'">
        运行方式
      </el-row>
      <el-row v-if="activeName === 'fourth'">
        接地线（刀闸）
      </el-row>
      <el-row v-if="activeName === 'fifth'">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="日期" prop="date">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="form.date"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="班次">
            <el-radio-group v-model="form.type">
              <el-radio
                v-for="dict in typeOptions"
                :key="dict.dictValue"
                :label="parseInt(dict.dictValue)"
              >{{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="负责人" prop="logUser">
            <el-input v-model="form.logUser" placeholder="请输入负责人"/>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select v-model="form.status" placeholder="请选择状态">
              <el-option
                v-for="dict in statusOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="parseInt(dict.dictValue)"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <!--        <div slot="footer" class="dialog-footer">-->
        <!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <!--          <el-button @click="cancel">取 消</el-button>-->
        <!--        </div>-->
      </el-row>
      <el-row v-if="activeName === 'sixth'">
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddOrder"
              v-hasPermi="['system:logOrders:add']"
            >新增</el-button>
          </el-col>
        </el-row>
        <el-table v-loading="loadingOrder" :data="logOrdersList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="序号" align="center" prop="id" key="1" />
          <el-table-column label="时间" align="center" prop="time" width="180" key="2">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.time, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="调度" align="center" prop="dispatch" key="3" />
          <el-table-column label="发令人" align="center" prop="sender" key="4" />
          <el-table-column label="联系内容" align="center" prop="text" key="5" />
          <el-table-column label="收令人" align="center" prop="receiver" key="6" />
          <el-table-column label="日志id" align="center" prop="logId" key="7" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" key="8">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdateOrder(scope.row)"
                v-hasPermi="['system:logOrders:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:logOrders:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
    </el-dialog>
    <!-- 添加或修改运行记事对话框 -->
    <el-dialog :title="titleDiary" :visible.sync="openDiary" width="500px" append-to-body>
      <el-form ref="formDiary" :model="formDiary" :rules="rules" label-width="80px">
        <el-form-item label="记录类型" prop="type">
          <el-select v-model="formDiary.type" placeholder="请选择记录类型">
            <el-option
              v-for="dict in typeOptions2"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="记录内容" prop="text">
          <el-input v-model="formDiary.text" type="textarea" placeholder="请输入内容"/>
        </el-form-item>
        <el-form-item label="负责人" prop="userName">
          <el-input v-model="formDiary.userName" placeholder="请输入负责人"/>
        </el-form-item>
        <el-form-item label="日志编号" prop="logId">
          <el-input v-model="formDiary.logId" placeholder="请输入日志编号"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormDiary">确 定</el-button>
        <el-button @click="cancelDiary">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改调度命令对话框 -->
    <el-dialog :title="titleOrder" :visible.sync="openOrder" width="500px" append-to-body>
      <el-form ref="form" :model="formOrder" :rules="rules" label-width="80px">
        <el-form-item label="时间" prop="time">
          <el-date-picker clearable size="small" style="width: 200px"
                          v-model="formOrder.time"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="选择时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="调度" prop="dispatch">
          <el-input v-model="formOrder.dispatch" placeholder="请输入调度" />
        </el-form-item>
        <el-form-item label="发令人" prop="sender">
          <el-input v-model="formOrder.sender" placeholder="请输入发令人" />
        </el-form-item>
        <el-form-item label="内容" prop="text">
          <el-input v-model="formOrder.text" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="收令人" prop="receiver">
          <el-input v-model="formOrder.receiver" placeholder="请输入收令人" />
        </el-form-item>
        <el-form-item label="日志id" prop="logId">
          <el-input v-model="formOrder.logId" placeholder="请输入日志id" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormOrder">确 定</el-button>
        <el-button @click="cancelOrder">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改日志工作安排对话框 -->
    <el-dialog :title="titleWork" :visible.sync="openWork" width="500px" append-to-body key="Work">
      <el-form ref="form" :model="formWork" :rules="rules" label-width="80px">
        <el-form-item label="工作内容" prop="text">
          <el-input v-model="formWork.text" placeholder="请输入工作内容" />
        </el-form-item>
        <el-form-item label="负责人" prop="user">
          <el-input v-model="formWork.user" placeholder="请输入负责人" />
        </el-form-item>
        <el-form-item label="完成情况">
          <el-radio-group v-model="formWork.status">
            <el-radio
              v-for="dict in statusOptions1"
              :key="dict.dictValue"
              :label="parseInt(dict.dictValue)"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="日志编号" prop="logId">
          <el-input v-model="formWork.logId" placeholder="请输入日志编号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormWork">确 定</el-button>
        <el-button @click="cancelWork">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listLog, getLog, delLog, addLog, updateLog, exportLog} from "@/api/system/log";
import {addDiary, getDiary, listDiary, updateDiary} from "@/api/system/diary";
import {addLogOrders, getLogOrders, listLogOrders, updateLogOrders} from "@/api/system/logOrders";
import {addWorklist, getWorklist, listWorklist, updateWorklist} from "@/api/system/worklist";
import {getMeetings} from "@/api/system/meetings";

export default {
  name: "Log",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 运行记事遮罩层
      loadingDiary: true,
      // 调度命令遮罩层
      loadingOrder: true,
      // 工作安排遮罩层
      loadingWork: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 运行日志表格数据
      logList: [],
      // 运行记事表格数据
      diaryList: [],
      // 调度命令表格数据
      logOrdersList: [],
      // 工作安排表格数据
      worklistList: [],
      // 弹出层标题
      title: "",
      // 弹出层记事标题
      titleDiary: "",
      // 弹出层日志标题
      titleLog: "",
      // 弹出层日志标题
      titleOrder: "",
      // 弹出层工作安排标题
      titleWork: "",
      // 是否显示弹出层
      open: false,
      // 是否显示运行记事弹出层
      openDiary: false,
      // 是否显示运行日志弹出层
      openLog: false,
      // 是否显示调度命令弹出层
      openOrder: false,
      // 是否显示工作安排弹出层
      openWork: false,
      // 班次(0 白班 1夜班)字典
      typeOptions: [],
      // 工作安排字典
      statusOptions1: [],
      // 记录类型字典
      typeOptions2: [],
      // 状态(0 未交班 1 已交班 2已接班)字典
      statusOptions: [],
      // 填充id
      idStorage: null,
      idStorage1: null,
      idStorage2: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        date: null,
        type: null,
        shiftTime: null,
        takeTime: null,
        logUser: null,
        status: null
      },

      // 运行记事查询参数
      queryDiaryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        userName: null,
        logId: null
      },
      // 调度命令查询参数
      queryParamsOrder: {
        pageNum: 1,
        pageSize: 10,
        time: null,
        dispatch: null,
        sender: null,
        receiver: null,
        logId: null
      },
      // 工作安排查询参数
      queryParamsWork: {
        pageNum: 1,
        pageSize: 10,
        user: null,
        status: null,
        logId: null
      },
      activeName: 'first',
      // 表单参数
      form: {},
      // 运行记事表单参数
      formDiary: {},
      // 调度命令表单参数
      formOrder: {},
      // 工作安排表单参数
      formWork: {},
      // 会议表单参数
      formMeet: {},
      // 表单校验
      rules: {
        date: [
          {required: true, message: "日期不能为空", trigger: "blur"}
        ],
        type: [
          {required: true, message: "班次不能为空", trigger: "blur"}
        ],
        logUser: [
          {required: true, message: "负责人不能为空", trigger: "blur"}
        ],
        status: [
          {required: true, message: "状态不能为空", trigger: "change"}
        ]
      }
    };
  },
  created() {
    this.getList();
    this.getListDiary();
    this.getListOrder();
    this.getListWork();
    this.getDicts("sys_work_log_type").then(response => {
      this.typeOptions = response.data;
    });
    this.getDicts("sys_work_log_status").then(response => {
      this.statusOptions = response.data;
    });
    this.getDicts("log_diary_type").then(response => {
      this.typeOptions2 = response.data;
    });
    this.getDicts("log_worklist_status").then(response => {
      this.statusOptions1 = response.data;
    });
  },
  methods: {
    /** 查询运行日志列表 */
    getList() {
      this.loading = true;
      listLog(this.queryParams).then(response => {
        this.logList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 班次(0 白班 1夜班)字典翻译
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.type);
    },
    // 状态(0 未交班 1 已交班 2已接班)字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.openLog = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        logId: null,
        date: null,
        type: 0,
        shiftTime: null,
        takeTime: null,
        logUser: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.logId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.worklistList = [];
      this.diaryList = [];
      this.logOrdersList = [];
      this.resetMeet();
      this.reset();
      this.openLog = true;
      this.titleLog = "添加交班记录";
      this.open = true;
      this.title = "添加运行日志";
    },
    setAll(logId){
      this.getListWork(logId);
      this.getListDiary(logId);
      this.getListOrder(logId);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      this.resetMeet();
      const logId = row.logId || this.ids
      this.idStorage1 = logId;
      this.setAll(logId);
      getMeetings(logId).then(response => {
        this.formMeet = response.data;
        this.open = true;
        this.title = "修改运行日志";
        if (this.formMeet == null){
          this.resetMeet();
        }
      });

      // getLog(logId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改运行日志";
      // });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.logId != null) {
            updateLog(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.openLog = false;
              this.getList();
            });
          } else {
            addLog(this.form).then(response => {
              this.idStorage = response.data
              this.msgSuccess("新增成功");
              this.openLog = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const logIds = row.logId || this.ids;
      this.$confirm('是否确认删除运行日志编号为"' + logIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delLog(logIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有运行日志数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportLog(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 新增运行记事按钮操作 */
    handleAddDiary() {
      this.resetDiary();
      this.openDiary = true;
      this.titleDiary = "添加运行记事";
    },
    /** 修改按钮操作 */
    handleUpdateDiary(row) {
      this.resetDiary();
      const diaryId = row.diaryId || this.ids
      getDiary(diaryId).then(response => {
        this.formDiary = response.data;
        this.openDiary = true;
        this.titleDiary = "修改运行记事";
      });
    },
    // 运行记事表单重置
    resetDiary() {
      this.formDiary = {
        diaryId: null,
        type: null,
        text: null,
        userName: null,
        logId: null
      };
      this.resetForm("form");
    },
    idChange(){
      this.idStorage = null;
    },
    /** 提交按钮 */
    submitFormDiary() {
      this.$refs["formDiary"].validate(valid => {
        if (valid) {
          let logId = this.idStorage1;
          if (this.formDiary.diaryId != null) {
            updateDiary(this.formDiary).then(response => {
              this.msgSuccess("修改成功");
              this.openDiary = false;
              this.getListDiary(logId);
            });
          } else {
            if(this.idStorage){
              this.formDiary.logId = this.idStorage;
            } else {
              this.formDiary.logId = this.idStorage1;
            }
            addDiary(this.formDiary).then(response => {
              this.msgSuccess("新增成功");
              this.openDiary = false;
              this.getListDiary(this.formDiary.logId);
            });
          }
        }
      });
    },
    // 取消运行记事按钮
    cancelDiary() {
      this.openDiary = false;
      this.resetDiary();
    },
    /** 查询运行记事列表 */
    getListDiary(logId) {
      this.loadingDiary = true;
      this.queryDiaryParams.logId = logId;
      listDiary(this.queryDiaryParams).then(response => {
        this.diaryList = response.rows;
        this.total = response.total;
        this.loadingDiary = false;
      });
    },
    // 记录类型字典翻译
    typeFormatDiary(row, column) {
      return this.selectDictLabel(this.typeOptions2, row.type);
    },
    /** 修改调度命令按钮操作 */
    handleUpdateOrder(row) {
      this.resetOrder();
      const id = row.id || this.ids
      getLogOrders(id).then(response => {
        this.formOrder = response.data;
        this.openOrder = true;
        this.titleOrder = "修改调度命令";
      });
    },
    /** 新增调度命令按钮操作 */
    handleAddOrder() {

      this.resetOrder();
      this.openOrder = true;
      this.titleOrder = "添加调度命令";
    },
    /** 查询调度命令列表 */
    getListOrder(logId) {
      this.loadingOrder = true;
      this.queryParamsOrder.logId = logId;
      listLogOrders(this.queryParamsOrder).then(response => {
        this.logOrdersList = response.rows;
        this.total = response.total;
        this.loadingOrder = false;
      });
    },
    /** 提交按钮 */
    submitFormOrder() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let logId = this.idStorage1;
          if (this.formOrder.id != null) {
            updateLogOrders(this.formOrder).then(response => {
              this.msgSuccess("修改成功");
              this.openOrder = false;
              this.getListOrder(logId);
            });
          } else {
            if(this.idStorage){
              this.formOrder.logId = this.idStorage;
            } else {
              this.formOrder.logId = this.idStorage1;
            }
            addLogOrders(this.formOrder).then(response => {
              this.msgSuccess("新增成功");
              this.openOrder = false;
              this.getListOrder(this.formOrder.logId);
            });
          }
        }
      });
    },
    // 取消按钮
    cancelOrder() {
      this.openOrder = false;
      this.resetOrder();
    },
    // 表单重置
    resetOrder() {
      this.formOrder = {
        id: null,
        time: null,
        dispatch: null,
        sender: null,
        text: null,
        receiver: null,
        logId: null
      };
      this.resetForm("form");
    },

    /** 新增按钮操作 */
    handleAddWork() {
      this.resetWork();
      this.openWork = true;
      this.titleWork = "添加日志工作安排";
    },
    /** 修改工作安排按钮操作 */
    handleUpdateWork(row) {
      this.resetWork();
      const id = row.id || this.ids
      getWorklist(id).then(response => {
        this.formWork = response.data;
        this.openWork = true;
        this.titleWork = "修改日志工作安排";
      });
    },
    /** 查询工作安排列表 */
    getListWork(logId) {
      this.loadingWork = true;
      this.queryParamsWork.logId = logId;
      listWorklist(this.queryParamsWork).then(response => {
        this.worklistList = response.rows;
        this.total = response.total;
        this.loadingWork = false;
      });
    },
    // 完成情况字典翻译
    statusFormatWork(row, column) {
      return this.selectDictLabel(this.statusOptions1, row.status);
    },
    /** 提交按钮 */
    submitFormWork() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let logId = this.idStorage1;
          if (this.formWork.id != null) {
            updateWorklist(this.formWork).then(response => {
              this.msgSuccess("修改成功");
              this.openWork = false;
              this.getListWork(logId);
            });
          } else {
            if(this.idStorage){
              this.formWork.logId = this.idStorage;
            } else {
              this.formWork.logId = this.idStorage1;
            }
            addWorklist(this.formWork).then(response => {
              this.msgSuccess("新增成功");
              this.openWork = false;
              this.getListWork(this.formWork.logId);
            });
          }
        }
      });
    },
    // 表单重置
    resetWork() {
      this.formWork = {
        id: null,
        text: null,
        user: null,
        status: 0,
        logId: null
      };
      this.resetForm("form");
    },
    // 取消按钮
    cancelWork() {
      this.openWork = false;
      this.resetWork();
    },
    // 表单重置
    resetMeet() {
      this.formMeet = {
        id: null,
        preMeeting: null,
        preUser: null,
        postMeeting: null,
        postUser: null,
        logId: null
      };
      this.resetForm("form");
    },
  }
};
</script>
